home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / misc / emu / Easy1541.lha / Easy1541 / dev / Examples / IECDir.c < prev    next >
C/C++ Source or Header  |  1996-10-06  |  2KB  |  147 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <dos.h>
  5.  
  6. #include <exec/exec.h>
  7. #include <exec/execbase.h>
  8. #include <exec/memory.h>
  9. #include <proto/exec.h>
  10. #include <proto/dos.h>
  11.  
  12. #include <iec/iec.h>
  13.  
  14. //----------------------------------------
  15. //IECDir 1.1
  16. //
  17. //Displays the directory of the disk inserted
  18. //the 1541 drive.
  19. //
  20. //----------------------------------------
  21.  
  22. struct iecbase *IECBase;
  23.  
  24. char Version[]="$VER:IECDir 1.1 (06.10.96) by Fabrizio Farenga";
  25. UWORD BlockSize;
  26. unsigned char c1,c2;
  27.  
  28.  
  29. struct RDArgs *rda;
  30. LONG argv[1]={0};
  31. char device=8;    //Default device #
  32.  
  33. /* Break Handler */
  34. int brk(void)
  35. {
  36. /* On break, close all */
  37.  
  38. Listen(device);    //CLOSE
  39. Second(CMD_CLOSE+0);
  40. UnListen();
  41.  
  42. CloseLibrary((struct Library*)IECBase);
  43.  
  44. printf ("\nBreak received.\n\n");
  45. return (1);
  46. }
  47.  
  48.  
  49. void ReadDir(void)
  50. {
  51. printf ("\n");
  52.  
  53. //Ask for the directory (LOAD"$",device)
  54. Listen(device);
  55. Second(CMD_OPEN+0);
  56.  
  57. if (IECBase->iec_ST!=ST_OK)
  58.     {
  59.     printf ("?DEVICE NOT PRESENT\n\n");
  60.     return;
  61.     }
  62.         
  63. CIOut('$');
  64. UnListen();
  65.  
  66. Talk(device);    //Start receiving data
  67. TkSA(CMD_DATA+0);
  68.  
  69. ACPtr();    //Ignore load-address
  70. ACPtr();
  71.  
  72.     while (IECBase->iec_ST==ST_OK)
  73.     {
  74.     ACPtr();    //Ignore line-start 1st byte
  75.     if (IECBase->iec_ST!=ST_OK) break;
  76.     ACPtr();    //Ignore line-start 2nd byte
  77.     if (IECBase->iec_ST!=ST_OK) break;
  78.  
  79.     c1=ACPtr();    //Read the block size low-byte
  80.     if (IECBase->iec_ST!=ST_OK) break;
  81.     c2=ACPtr(); //Read the block size hi-byte
  82.     if (IECBase->iec_ST!=ST_OK) break;
  83.  
  84.     //Print the block size
  85.     BlockSize=c1+(c2<<8);
  86.     printf ("%d ",BlockSize);
  87.  
  88.         //Get the first character of the line
  89.         c1=ACPtr();
  90.         do
  91.         {
  92.  
  93.             //If character is 0x12 (REVSON), turn on the REVERSE-VIDEO mode
  94.             if (c1!=0x12) printf ("%c",c1);
  95.             else printf ("m");
  96.  
  97.         //Get the next character
  98.         c1=ACPtr();
  99.         if (IECBase->iec_ST!=ST_OK) break;
  100.         } while (c1!=0);    //Wait for end of line (NULL)
  101.     printf ("m\n");    //Turn off the REVERSE-VIDEO mode
  102.     }
  103.  
  104. UnTalk();
  105.  
  106. Listen(device);    //CLOSE
  107. Second(CMD_CLOSE+0);
  108. UnListen();
  109.  
  110. printf ("\n");
  111. }
  112.  
  113.  
  114. void main(void)
  115. {
  116.  
  117. if ((rda = ReadArgs("Device/N",argv,NULL)) != NULL)
  118.     {
  119.     if (argv[0]!=0) device=*(LONG *)argv[0];    //Get the device number
  120.     FreeArgs(rda);
  121.     }
  122.  
  123. if (device<4)
  124.     {
  125.     printf ("\n?DEVICE NOT PRESENT\n\n");
  126.     return;
  127.     }
  128.  
  129. IECBase = (struct iecbase*)OpenLibrary("iec.library",0L);
  130.  
  131. if (IECBase!=0)
  132.     {
  133.  
  134.     /*Set the break handler*/
  135.     onbreak(&brk);
  136.  
  137.     ReadDir();
  138.  
  139.     CloseLibrary((struct Library*)IECBase);
  140.     }
  141. else
  142.     {
  143.     printf ("Can't open iec.library\n");
  144.     return;
  145.     }
  146. }
  147.